from django.core.context_processors import csrf
from django.core.mail import send_mail
from django.http import HttpResponse
from django.shortcuts import render_to_response, redirect
from solar.activity.form import RegistrationForm
from solar.activity.models import Registration

def demoshow(request):
    c = {}
    c.update(csrf(request))
    if request.method == 'POST':   
        form = RegistrationForm(request.POST)
        
        if form.is_valid():
            cd = form.cleaned_data
            reg = Registration.objects.create(name=cd['name'], 
                                              gender=cd['gender'],
                                              phone=cd['phone'],
                                              email=cd['email'],
                                              org=cd['org'],
                                              department=cd['department'],
                                              status=cd['status'],
                                              )
            return redirect('/registration/')
    else:
        form = RegistrationForm()
    c.update({'form':form})
    c.update({'post_data':request.POST})   
    c.update({'demostatus':'active'}) 
    
    return render_to_response('demoshow.html', c)

def finishRegistration(request):
    return render_to_response('registration.html')

def mail(request):
    send_mail('New iPad', 'Hello World', 'service@appuniverz.org.tw',
    ['aquilading@gmail.com'], fail_silently=False)
    return HttpResponse('success')